﻿package kaze.process.application 
{
    import kaze.models.ModelList;

    import system.process.Initializer;

    import vegas.config.Config;
    import vegas.ioc.factory.ObjectFactory;
    import vegas.models.maps.MapModelObject;
    import vegas.net.FlashVars;
    /**
     * This controller initialize the application when all externals assets and configs are loading and initialize.
     */
    public class InitApplication extends Initializer 
    {
        /**
         * Creates a new InitApplication instance.
         */
        public function InitApplication()
        {
            //
        }
        
        /**
         * The IoC factory reference.
         */
        public var factory:ObjectFactory ;
        
        /**
         * The FlashVars reference of the application.
         */
        public var flashVars:FlashVars ;
        
        /**
         * Invoked when the process is run.
         */
        public function initialize():void 
        {
            var defaultID:String  = Config.getInstance().get("defaultID") as String ;
            if ( flashVars && flashVars.contains( "defaultID" ) )
            {
                defaultID = flashVars.getValue( "defaultID" ) ;
            }
            
            logger.debug ( this + " init default:" + defaultID ) ; 
            
            var menu:MapModelObject = factory.getObject( ModelList.MENU_MODEL  ) as MapModelObject ;
            if ( menu != null && defaultID != null && menu.containsByID( defaultID  ))
            {
                menu.setCurrentVO( menu.getVO( defaultID ) ) ;
            }
        }
    }
}